package tp.pr1;

public enum Direction {
	EAST, NORTH, SOUTH, WEST, UNKNOWN;

	/**
	 * Obtiene la direccion opuesta ( punto cardinal )
	 * 
	 * @return la direccion (enum) opuesta
	 */
	public Direction opposite() {
		Direction opp = UNKNOWN;
		switch (this) {
		case EAST:
			opp = WEST;
			break;
		case NORTH:
			opp = SOUTH;
			break;
		case SOUTH:
			opp = NORTH;
			break;
		case WEST:
			opp = EAST;
			break;
		default:
			opp = UNKNOWN;
		}
		return opp;
	}

	/**
	 * Obtiene una nueva direccion aplicando el parametro rotation (realiza el
	 * giro a derecha o izquierda)
	 * 
	 * @return la nueva direccion
	 */
	public Direction rotate(Rotation rotation) {
		Direction ret = null;
		switch (this) {
		case EAST:
			if (rotation == Rotation.LEFT)
				ret = Direction.NORTH;
			else if (rotation == Rotation.RIGHT)
				ret = Direction.SOUTH;
			break;
		case NORTH:
			if (rotation == Rotation.LEFT)
				ret = Direction.WEST;
			else if (rotation == Rotation.RIGHT)
				ret = Direction.EAST;
			break;
		case SOUTH:
			if (rotation == Rotation.LEFT)
				ret = Direction.EAST;
			else if (rotation == Rotation.RIGHT)
				ret = Direction.WEST;
			break;
		case WEST:
			if (rotation == Rotation.LEFT)
				ret = Direction.SOUTH;
			else if (rotation == Rotation.RIGHT)
				ret = Direction.NORTH;
			break;
		default:
			ret = this;
			break;
		}
		return ret;
	}
}
